package com.cskaoyan.controller;

import com.cskaoyan.bean.PermissionInsert;
import com.cskaoyan.mapper.PermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PermissionInsertController {

    @Autowired
    PermissionMapper permissionMapper;

    @RequestMapping("/permission")
    public void permission(@RequestBody PermissionInsert permission) {


        //分别拆成三张表的内容
        List<PermissionInsert.SystemPermissionsBean> systemPermissions = permission.getSystemPermissions();

        for (PermissionInsert.SystemPermissionsBean systemPermission : systemPermissions) {

            int i = permissionMapper.insertOne(systemPermission);
            //拿到id
            Integer oneId = systemPermission.getIid();

            List<PermissionInsert.SystemPermissionsBean.ChildrenBeanX> childrenX = systemPermission.getChildren();

            for (PermissionInsert.SystemPermissionsBean.ChildrenBeanX childrenBeanX : childrenX) {

                childrenBeanX.setPid(oneId);

                int j = permissionMapper.insertTwo(childrenBeanX);
                //取出id
                Integer twoId = childrenBeanX.getIid();

                List<PermissionInsert.SystemPermissionsBean.ChildrenBeanX.ChildrenBean> children = childrenBeanX.getChildren();

                for (PermissionInsert.SystemPermissionsBean.ChildrenBeanX.ChildrenBean child : children) {
                    child.setPid(twoId);

                    int k = permissionMapper.insertThree(child);
                }
            }
        }
    }
}
